package com.usian.admin.listener;

import com.usian.admin.service.WemediaNewsAutoScanService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class WemediaNewsAutoListener {

    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @KafkaListener(topics = {"wemediazidongshenhe"})
    public void test(ConsumerRecord<?,?> record){
        Optional<? extends ConsumerRecord<?, ?>> optional = Optional.ofNullable(record);
//        if(optional.isPresent()){
//            Object newsId = record.value();
//            int i = Integer.parseInt(newsId.toString());
//            System.out.println("kafka自动审核====="+newsId);
//            wemediaNewsAutoScanService.newAutoScan(i);
//        }
        if(optional.isPresent()){
            String newsId = (String) record.value();
            System.out.println("kafka自动审核====="+newsId);
            wemediaNewsAutoScanService.newAutoScan(Integer.valueOf(newsId));
        }
    }
}